package Bio::Rambam::Proteomics::Ms2;

use Moose;
use namespace::autoclean;
extends 'Bio::Rambam::Proteomics::Formats::Peaklist';

sub add_spectrum_ms2{
	my ($self, $spectrum_object) = @_;
	return unless $spectrum_object;
	return unless $spectrum_object->id;
	return unless $spectrum_object->precursor_mz;
	return unless $spectrum_object->array_int_translated;
	return unless $spectrum_object->array_mz_translated;
	
	open MS2,">>",$self->file;
	my $ms2_TITLE=$self->filename;
	$ms2_TITLE=~s/\.ms2$//;
	print MS2 "\nH	Source file	$ms2_TITLE\n";
	# The TITLE: I'm using the mzml->run_id->spectrumList->spectrum->@id
	
	print MS2 "S\t".$spectrum_object->index."\t".$spectrum_object->index."\t".sprintf("%.4f",$spectrum_object->precursor_mz) if (defined $spectrum_object->index and defined $spectrum_object->precursor_mz);
	print MS2 "\n" if defined $spectrum_object->precursor_mz;
	for(my $i=0;$i<=$#{$spectrum_object->array_mz_translated};$i++){
		print MS2 sprintf("%.4f",${$spectrum_object->array_mz_translated}[$i]);
		print MS2 " ";
		print MS2 sprintf("%.2f",${$spectrum_object->array_int_translated}[$i]);
		print MS2 "\n";
	}
	print MS2 "\n";
	close MS2;
	
}








__PACKAGE__->meta->make_immutable;